<!--钱包管理-->
<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                   v-hasPermi="['car:user:add']"
        >新增
        </el-button>
      </el-col>
    </el-row>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="钱包网络" align="center" prop="network" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="可用状态" align="center" prop="state" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.state" active-color="#13ce66" inactive-color="#ff4949" :active-value="1"
                     :inactive-value="0" @change="statusChange(scope.row)"
          />
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy" width="180" :show-overflow-tooltip="true"/>
      <el-table-column label="更新时间" align="center" prop="updateTime" width="180"
                       :show-overflow-tooltip="true"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{m}/{d}/{y}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <div>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleUpdate(scope.row)">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />
    <!-- 添加或修改 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" >
        <el-form-item label="钱包网络" prop="network" :rules="[{ required: true, message: '请输入网络钱包名称', trigger: 'blur' }]">
          <el-input v-model="form.network" placeholder="请输入理财明细数量"/>
        </el-form-item>
        <el-form-item label="是否可用" prop="state" :rules="[{ required: true, message: '请选择可用状态', trigger: 'blur' }]">
          <el-radio v-model="form.state" :label="1">可用</el-radio>
          <el-radio v-model="form.state" :label="0">不可用</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { manageList, deleteManageData, manageDataDetails, addManageData, updateState } from '@/api/bank/wallent'
import OssImagePreview from '@/components/ImagePreview/oss-image-preview.vue'
import { changeStatus } from '@/api/store/storeProduct'

export default {
  name: 'bankCardManage',
  components: { OssImagePreview },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 用户完成线下理财信息表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      open: false,
      title: '',
      // 表单参数
      form: {state:1},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询用户完成线下理财信息列表 */
    getList() {
      this.loading = true
      manageList(this.queryParams).then(response => {
        this.dataList = response.data.records
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id
      this.$modal.confirm('是否确认删除钱包编号为"' + id + '"的数据项？').then(function() {
        return deleteManageData([id])
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 新增 */
    handleAdd(row) {
      this.reset()
      this.open = true
      this.title = '添加钱包'
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        network: null,
        state: 1
      }
      this.resetForm('form')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      manageDataDetails(row.id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改钱包'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          addManageData(this.form).then(response => {
            this.$modal.msgSuccess('新增成功')
            this.open = false
            this.getList()
          })
        }
      })
    },
    /** 修改状态 */
    statusChange(row) {
      updateState(row.id).then(response => {
        this.$modal.msgSuccess('修改成功')
        this.getList()
      })
    }
  }
}
</script>
